CMAKE_MINIMUM_REQUIRED( VERSION 2.6 )

project( gloox )

SET( CPACK_PACKAGE_DESCRIPTION_SUMMARY "A Jabber/XMPP library" )
SET( CPACK_PACKAGE_VENDOR "Jakob Schröter" )
SET( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README" )
SET( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" )
SET( CPACK_PACKAGE_VERSION_MAJOR "1" )
SET( CPACK_PACKAGE_VERSION_MINOR "1" )
SET( CPACK_PACKAGE_VERSION_PATCH "svn" )
SET( CPACK_SOURCE_GENERATOR "TBZ2" )
set( CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}" )
set( CPACK_SOURCE_IGNORE_FILES "/build/;/.svn/;~$;${CPACK_SOURCE_IGNORE_FILES}" )
SET( CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_PROJECT_NAME}-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}-${CMake_VERSION_PATCH}" )
include( CPack )


set( GLOOX_ENABLE_MAINTAINER false CACHE BOOL "Enable Maintainer Mode" )
set( GLOOX_ENABLE_GETADDRINFO false CACHE BOOL "Enable getaddrinfo()" )
if( WIN32 )
        set( GLOOX_WITH_SCHANNEL false CACHE BOOL "Enable SChannel" )
endif( WIN32 )

set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/" )

if( GLOOX_ENABLE_MAINTAINER )
        set( CMAKE_CXX_FLAGS "-Wshadow -Werror" CACHE STRING "Maintainer Flags" FORCE )
endif( GLOOX_ENABLE_MAINTAINER )

set( CMAKE_CXX_FLAGS_DEBUG "-g3 -fno-inline -DDEBUG" CACHE STRING "Debug Flags" FORCE )

find_package( GNUTLS )
find_package( OpenSSL )
find_package( ZLIB )
find_package( IDN )
find_package( Threads )

include( CheckFunctionExists )

## Check functions
check_function_exists( setsockopt SETSOCKOPT_EXISTS )
if(NOT WIN32)
#SET( CMAKE_REQUIRED_FLAGS "-fno-builtin" )
SET( CMAKE_REQUIRED_LIBRARIES "resolv" ) # FIXME
        check_function_exists( res_querydomain QUERYDOMAIN_EXISTS )
        check_function_exists( dn_skipname SKIPNAME_EXISTS )
        check_function_exists( res_query QUERY_EXISTS )
endif(NOT WIN32)

if( GLOOX_ENABLE_GETADDRINFO )
        check_function_exists( getaddrinfo GETADDRINFO_EXISTS )
        if( GETADDRINFO_EXISTS )
                set( HAVE_GETADDRINFO true )
        endif( GETADDRINFO_EXISTS )
endif( GLOOX_ENABLE_GETADDRINFO )

if( SETSOCKOPT_EXISTS )
        set( HAVE_SETSOCKOPT true )
endif( SETSOCKOPT_EXISTS )


## Zlib
if( ZLIB_FOUND )
        list( APPEND LIBS ${ZLIB_LIBRARIES} )
        list( APPEND INCLUDE_DIRS ${ZLIB_INCLUDE_DIR} )
        set( HAVE_ZLIB true )
endif( ZLIB_FOUND )

## SSL/TLS
if( GNUTLS_FOUND )
        list( APPEND LIBS ${GNUTLS_LIBRARIES} )
        list( APPEND INCLUDE_DIRS ${GNUTLS_INCLUDE_DIRS} )
        set( HAVE_GNUTLS true )
else( GNUTLS_FOUND )
        if( OPENSSL_FOUND )
                list( APPEND LIBS ${OPENSSL_LIBRARIES} )
                list( APPEND INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR} )
                set( HAVE_OPENSSL true )
        endif( OPENSSL_FOUND )
endif( GNUTLS_FOUND )

## IDN
if( IDN_FOUND )
        add_definitions( ${IDN_DEFINITIONS} )
        list( APPEND LIBS ${IDN_LIBRARIES} )
        list( APPEND INCLUDE_DIRS ${IDN_INCLUDE_DIR} )
        set( HAVE_LIBIDN true )
endif( IDN_FOUND )

## Windows/Pthreads
if( WIN32 )
        list( APPEND LIBS "-lwsock32 -lgdi32 -ldnsapi" )
        if( GLOOX_WITH_SCHANNEL )
                list( LIBS APPEND "-lcrypt32 -lsecur32" )
        endif( GLOOX_WITH_SCHANNEL )
        set( HAVE_WINTLS true )
        set( HAVE_WINDNS_H true )
else( WIN32 )
        if( CMAKE_USE_PTHREADS_INIT )
                set( HAVE_PTHREAD true )
        else( CMAKE_USE_PTHREADS_INIT )
                message( FATAL_ERROR "we do need pthread support!" )
        endif( CMAKE_USE_PTHREADS_INIT )
endif( WIN32 )

configure_file( ${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h.unix )

enable_testing()
add_test( adhoc_test adhoc_test )
add_test( adhoccommand_test adhoccommand_test )
add_test( adhoccommandnote_test adhoccommandnote_test )
add_test( amprule_test amprule_test )
add_test( amp_test amp_test )
add_test( asyncdns_test asyncdns_test )
add_test( base64_test base64_test )
add_test( capabilities_test capabilities_test )
add_test( chatstatefilter_test chatstatefilter_test )
add_test( client_test client_test )
add_test( clientbase_test clientbase_test )
add_test( connectionbosh_test connectionbosh_test )
add_test( dataform_test dataform_test )
add_test( dataformfield_test dataformfield_test )
add_test( dataformreported_test dataformreported_test )
add_test( dataformitem_test dataformitem_test )
add_test( delayeddelivery_test delayeddelivery_test )
add_test( discoinfo_test discoinfo_test )
add_test( discoitems_test discoitems_test )
add_test( disco_test disco_test )
add_test( error_test error_test )
add_test( featureneg_test featureneg_test )
add_test( flexoffline_test flexoffline_test )
add_test( flexofflineoffline_test flexofflineoffline_test )
add_test( gpgencrypted_test gpgencrypted_test )
add_test( gpgsigned_test gpgsigned_test )
add_test( inbandbytestreamibb_test inbandbytestreamibb_test )
add_test( inbandbytestream_test inbandbytestream_test )
add_test( iq_test iq_test )
add_test( jid_test jid_test )
add_test( jinglesessionjingle_test jinglesessionjingle_test )
add_test( jinglertp_test jinglertp_test )
add_test( jingleiceudp_test jingleiceudp_test )
add_test( jinglerawudp_test jinglerawudp_test )
add_test( jinglesession_test jinglesession_test )
add_test( lastactivity_test lastactivity_test )
add_test( lastactivityquery_test lastactivityquery_test )
add_test( md5_test md5_test )
add_test( message_test message_test )
add_test( messageeventfilter_test messageeventfilter_test )
add_test( mucroommuc_test mucroommuc_test )
add_test( mucroommucadmin_test mucroommucadmin_test )
add_test( mucroommucowner_test mucroommucowner_test )
add_test( mucroommucuser_test mucroommucuser_test )
add_test( nickname_test nickname_test )
add_test( nonsaslauthquery_test nonsaslauthquery_test )
add_test( nonsaslauth_test nonsaslauth_test )
add_test( oob_test oob_test )
add_test( parser_test parser_test )
add_test( prep_test prep_test )
add_test( presence_test presence_test )
add_test( privacymanager_test privacymanager_test )
add_test( privacymanagerquery_test privacymanagerquery_test )
add_test( privatexml_test privatexml_test )
add_test( pubsubmanagerpubsub_test pubsubmanagerpubsub_test )
add_test( pubsubmanager_test pubsubmanager_test )
add_test( pubsubevent_test pubsubevent_test )
add_test( receipt_test receipt_test )
add_test( registrationquery_test registrationquery_test )
add_test( registration_test registration_test )
add_test( rostermanagerquery_test rostermanagerquery_test )
add_test( rostermanager_test rostermanager_test )
add_test( searchquery_test searchquery_test )
add_test( search_test search_test )
add_test( sha_test sha_test )
add_test( shim_test shim_test )
add_test( simanager_test simanager_test )
add_test( simanagersi_test simanagersi_test )
add_test( stanzaextensionfactory_test stanzaextensionfactory_test )
add_test( subscription_test subscription_test )
add_test( tag_test tag_test )
add_test( tlsgnutls_test tlsgnutls_test )
add_test( tlsopenssl_test tlsopenssl_test )
add_test( uniquemucroomunique_test uniquemucroomunique_test )
add_test( vcard_test vcard_test )
add_test( vcardupdate_test vcardupdate_test )
add_test( xpath_test xpath_test )
add_test( zlib_test zlib_test )
add_test( util_test util_test )

add_subdirectory( src )
